import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import Fenlei from '@/components/Fenlei'
import Gouwuche from '@/components/Gouwuche'
import Shouye from '@/components/Shouye'
import Wode from '@/components/Wode'
import Detail from '@/components/Detail'
import Login from '@/components/Login'
import Code from '@/components/Code'
import Register from '@/components/Register'
import Edit from '@/components/Edit'
import Swipdetail from '@/components/Swipdetail'


Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/HelloWorld',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/Fenlei',
      name: 'Fenlei',
      component: Fenlei
    },
    {
      path: '/Gouwuche',
      name: 'Gouwuche',
      component: Gouwuche
    },
    {
      path: '/',
      name: 'Shouye',
      component: Shouye
    },
    {
      path: '/Wode',
      name: 'Wode',
      component: Wode
    },
    {
      path: '/Detail',
      name: 'Detail',
      component: Detail
    },

    {
      path: '/Login',
      name: 'Login',
      component: Login
    }
    ,
    {
      path: '/Register',
      name: 'Register',
      component: Register
    }
    ,
    {
      path: '/Code',
      name: 'Code',
      component: Code
    },
    {
      path: '/Edit',
      name: 'Edit',
      component: Edit
    },
    {
      path: '/Swipdetail',
      name: 'Swipdetail',
      component: Swipdetail
    },
    {
      path: '/search',
      name: 'Search',
      component: () => import("@/components/Search") //路由懒加载
    },



  ]
});

router.beforeEach((to,from,next)=>{
  console.log(to);
  if(to.path=="/Login" || to.path=="/Register" || to.path== "/Code" ){
    next()
  }else{
        if(sessionStorage.getItem("token")){
            next()
        }else{
          next("/Login")
        }

  }

})
export default router;

